import riskClient from "./riskClient";
import { getQueryString } from '@commonMethod'

export const decryptSceneTypeToPage = async () => {

  const params = {
    encryptData: getQueryString("encryptData"), //获取url中的encryptData参数
    partnerCode: getQueryString("partnerCode"), //获取url中的partnerCode参数
  };

  return await riskClient.postAsync({
    url: 'api/map/decryptSceneTypeToPage',
    params,
    auth:false,
  })

}

// 获取省市区
export const getAddressFindRegion = async (params) => {
  return await riskClient.postAsync({
    url: 'api/address/findRegion',
    params,
  })
};

// 获取机构
export const getUnits = async (params) => {
  const {data, error} = await riskClient.getAsync({
    url: 'api/map/getUnits',
    params,
    restfull: false
  })
  if (error) return
  const list = data.map(item => {
    return {value: item.unitCode, label: item.unitName}
  })
  sessionStorage.setItem('unitData', JSON.stringify(list))
};

// 获取险种
export const getRisks = async () => {
  const {data, error} = await riskClient.getAsync({url: 'api/map/getRisks', restfull: false})
  if (error) return
  const list = data.map(item => {
    return {value: item.riskCode, label: item.riskName}
  })
  sessionStorage.setItem('riskData', JSON.stringify(list))
};

// 获取省市区汇总数据
export const findAreaSubjectSum = async (params) => {
  return await riskClient.postAsync({
    url: 'api/subjectSum/findAreaSubjectSum',
    params,
  })
}

// 获取标记点的保单详情
export const findSubjectDetailByCondition = async (params) => {
  return await riskClient.postAsync({
    url: 'api/subjectDetail/findSubjectDetailByCondition',
    params,
  })
}

export const findRegion = async (params) => {
  return await riskClient.postAsync({
    url: 'api/address/findRegion',
    params,
  })
}
